//
//  PushNews.m
//  HYHOME
//
//  Created by cjy on 16/2/28.
//  Copyright © 2016年 Mac. All rights reserved.
//

#import "PushNews.h"
#import "PushNewsCell.h"
#import "NetHandleBlock.h"
#import "Taobao.h"
#import "DKNightVersion.h"
@interface PushNews ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,retain)UITableView *tableView;
@property (nonatomic,retain)NSMutableArray *array;

@end

@implementation PushNews

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    
    
    
    [self handle];
    [self createtableView];
    
}


- (void)handle{

    self.array = [NSMutableArray array];

    NSString *str = [NSString stringWithFormat:@"http://api.bohejiaju.com/v2/items/%@",self.idNumber];
    
    [NetHandleBlock networkingWithURL:str completeHandel:^(NSURLResponse *response, NSData *data, id result) {

     NSDictionary *dicD = [result objectForKey:@"data"];
        Model *model =[[ Model alloc]init];

        model.cover_image_url = [dicD objectForKey:@"cover_image_url"];
        model.name = [dicD objectForKey:@"name"];

        model.description1 = [dicD objectForKey:@"description"];
        model.price = [dicD objectForKey:@"price"];
        model.purchase_url = [dicD objectForKey:@"purchase_url"];
        [self.array addObject:model];
        
        [self.tableView reloadData];
        [model release];
    }];



}


- (void)createtableView{
    
    self.tableView = [[UITableView alloc]initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
    
    [self.view addSubview:self.tableView];
    [self.tableView release];
    
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    
    [self.tableView registerClass:[PushNewsCell class] forCellReuseIdentifier:@"pool"];

    self.tableView.dk_backgroundColorPicker = DKColorWithRGB(0xffffff, 0x343434);


}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return self.array.count;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{


    PushNewsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"pool"];
//    
     Model * model = [self.array objectAtIndex:indexPath.row];

//
  
    
    self.button = [[UILabel alloc]init];
    self.button.text = @"去淘宝看看";
   
    
    self.button.frame = CGRectMake(self.view.frame.size.width/2 + 50, 280, self.view.frame.size.width , 20);

    self.button.textColor = [UIColor whiteColor];
    
    [cell addSubview:self.button];
    
    cell.userInteractionEnabled = YES;
    
    [cell passModel:model];
    return cell;

}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row == 0) {
        
        Taobao *taobao = [[Taobao alloc]init];
        
        Model *model = [[Model alloc]init];
        model = self.array[indexPath.row];
        
        [taobao passModel:model];
        [self.navigationController pushViewController:taobao animated:YES];
    }
    


}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.row == 0) {
        return 300;
    }else {
    
        return 200;
    
    }
    


}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/


@end
